/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lesson3.slides.net;

import java.io.*;
import java.net.*;

public class ClientSocketExample {

    public static void main(String[] args) throws IOException {
        InetAddress addr = InetAddress.getByName(null);
        Socket connection = new Socket(addr, 8099);
        try {
            System.out.println("connection socket = " + connection);
            BufferedReader input = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));
            PrintWriter output = new PrintWriter(new BufferedWriter(
                    new OutputStreamWriter(connection.getOutputStream())), true);
            for (int i = 0; i < 10; i++) {
                output.println("Client generated line " + i);
                String s = input.readLine();
                System.out.println(s);
            }
            output.println("quit");
        } finally {
            System.out.println("Closing connection...");
            connection.close();
        }
    } //end main
} //end class
